package ch.elca.lol.puissance4.player.net;

import ch.elca.lol.puissance4.game.Token;
import ch.elca.lol.puissance4.player.Player;

public class Client extends Networker implements Player {
	
	public Client() {
		super(false);
	}
	
	@Override
	public void setToken(Token t) {
		log("negotiating token...");
		
		// Get server token
		int read = readInt();
		// Send own token
		writeInt(t.ordinal());
		
		// Tokens must not match
		if(read == t.ordinal()) {
			log("token mismatch.");
			close();
			throw new RuntimeException("token mismatch.");
		} else {
			log("token negotiation ok.");
		}
	}	
}
